package com.hunan.api.catv.service.biz.tencent_cloud.vod;

import com.google.gson.JsonObject;
import com.hunan.api.catv.common.Constants;
import com.hunan.api.catv.common.ConstantsMsg;
import com.hunan.api.catv.entity.ServiceResult;
import com.hunan.api.catv.service.ResultService;
import com.hunan.api.catv.service.biz.cache.CacheBiz;
import com.hunan.api.catv.service.impl.tencent_cloud.vod.VodService;
import com.hunan.api.catv.utils.GsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class VodBiz extends ResultService {

    @Autowired
    VodService vodService;

    @Autowired
    CacheBiz cacheBiz;

    public ServiceResult deleteMedia(String fileId) {
        JsonObject vodConf = GsonUtils.fromJson(cacheBiz.getSystemDict(Constants.tencent_cloud_vod_conf), JsonObject.class);
        if (!ObjectUtils.isEmpty(vodConf)) {
            String secretId = vodConf.get("secretId").getAsString();
            String secretKey = vodConf.get("secretKey").getAsString();
            boolean flag = vodService.deleteMedia(secretId, secretKey, fileId);
            if (flag) {
                return buildOK(true);
            }
        }
        return buildFail(ConstantsMsg.admin_del_fail);
    }
}
